******************************************************************
****                                                          ****
****     RATS386 batch program to replicate results from      ****
****    Box-Steffensmeier, Janet M. and Renee M. Smith. 1998. ****
****    "Investigating Political Dynamics Using Fractional    ****
****     Integration Methods" American Journal of Political   ****
****    Science. Forthcoming                                  ****
****                                                          ****
******************************************************************

* read in quarterly data
calendar 1953 1 4
allocate 1992:4
open data c:\finals\pub97\ajps\ajps2.dat
data(format=free,org=obs) / app sent mespart party events $
   assass iran viet water

* descriptive statistics for key variables
smpl 53:1 92:4
table / app sent mespart

* create administration dummy variables
set dde 53:1 60:4 = 1
set dde 61:1 92:4 = 0
set jfk 53:1 60:4 = 0
set jfk 61:1 61:1 = 1
set jfk 61:2 92:4 = 0
set lbj 53:1 63:3 = 0
set lbj 63:4 63:4 = 1
set lbj 64:1 92:4 = 0
set rmn 53:1 68:4 = 0
set rmn 69:1 69:1 = 1
set rmn 69:2 92:4 = 0
set grf 53:1 74:2 = 0
set grf 74:3 74:3 = 1
set grf 74:4 92:4 = 0
set jec 53:1 76:4 = 0
set jec 77:1 77:1 = 1
set jec 77:2 92:4 = 0
set rwr 53:1 80:4 = 0
set rwr 81:1 81:1 = 1
set rwr 81:2 92:4 = 0
set ghb 53:1 88:4 = 0
set ghb 89:1 89:1 = 1
set ghb 89:2 92:4 = 0

* rescale vietnam deaths variable
set nviet 53:1 92:4 = viet/1000

* create variable for iran-contra scandal
set contra 53:1 86:3 = 0
set contra 86:4 88:4 = 1
set contra 89:1 92:4 = 0

* create a new events series
* that combines separate events
set nevents 53:1 92:4 = events+iran+assass+contra

* create variable for gulf war
set gulf 53:1 90:4 = 0
set gulf 91:1 91:2 = 1
set gulf 91:3 92:4 = 0

* all variables previously coded for correctly signed
* effects on approval
* create new variables for macropartisanship equation
* by multiplying each by party variable
set psent 53:1 92:4 = party*sent
set pnviet 53:1 92:4 = party*nviet
set pwater 53:1 92:4 = party*water
set piran 53:1 92:4 = party*iran
set pevents 53:1 92:4 = party*events
set passass 53:1 92:4 = party*assass
set pcontra 53:1 92:4 = party*contra
set pgulf 53:1 92:4 = party*gulf
set pnevents 53:1 92:4 = party*nevents

* create political portion of approval
set resid 53:2 92:4 = app - .297*sent{-1}
set presid 53:2 92:4 = party*resid

* create first differences
set dresid 53:2 92:4 = resid - resid{-1}
print / dresid
set dpresid 53:2 92:4 = presid - presid{-1}
set dpsent 53:2 92:4 = psent - psent{-1}
set dmes 53:2 92:4 = mespart - mespart{-1}
set dapp 53:2 92:4 = app - app{-1}
set dsent 53:2 92:4 = sent - sent{-1}

* fractionally difference macropartisanship
declare series dfmes
source fif.src
@fif(d=-.213) dmes / dfmes

* descriptive statistics for dependent variables
smpl 53:4 92:2
table / mespart dfmes dmes

* create starting value for constant term
smpl 53:1 92:4
declare vect inita(1)
do i = 1,1
  compute inita(i)=-.005
end do i

* estimate ARMA model with levels of all variables
smpl 53:4 92:2
nlpar(subiterations=50)
boxjenk(constant,ar=1,inputs=13,initial=inita,iters=1500, $
   define=meseq1) mespart / resid1
# psent 0 1 0
# presid 0 1 0
# pnviet 0 0 0
# pwater 0 0 0
# pnevents 0 0 0
# pgulf 0 0 0
# jfk 0 0 0
# lbj 0 0 0
# rmn 0 0 0
# grf 0 0 0
# jec 0 0 0
# rwr 0 0 0
# ghb 0 0 0

* estimate effect of shock to macropartisanship
impulse(print) 1 20 1
# meseq1


* estimate ARFIMA model
* with fractionally differenced macropartisanship
smpl 53:4 92:2
nlpar(subiterations=50)
boxjenk(constant,ar=1,inputs=13,initial=inita,iters=300, $
   define=meseq2) dfmes / resid2
# psent 0 1 0
# presid 0 1 0
# pnviet 0 0 0
# pwater 0 0 0
# pnevents 0 0 0
# pgulf 0 0 0
# jfk 0 0 0
# lbj 0 0 0
# rmn 0 0 0
# grf 0 0 0
# jec 0 0 0
# rwr 0 0 0
# ghb 0 0 0

* estimate effect of shock to fractionally differenced
* macropartisanship
impulse(print) 1 20 1
# meseq2


* estimate ARIMA model with first differenced macropartisanship
smpl 53:4 92:2
nlpar(subiterations=50)
boxjenk(diffs=1,constant,ar=1,inputs=13,initial=inita, $
   iters=300,define=meseq3) mespart / resid3
# psent 0 1 0
# presid 0 1 0
# pnviet 0 0 0
# pwater 0 0 0
# pnevents 0 0 0
# pgulf 0 0 0
# jfk 0 0 0
# lbj 0 0 0
# rmn 0 0 0
# grf 0 0 0
# jec 0 0 0
# rwr 0 0 0
# ghb 0 0 0

* estimate effect of shock to first differenced
* macropartisanship
impulse(print) 1 20 1
# meseq3

halt


